//
//  Extension.swift
//  ReportScan
//
//  Created by woniu on 2025/7/22.
//

import Foundation
import AppKit

extension NSImage {
    
    func saveImage(to url: URL) -> Bool {
        guard let tiffData = self.tiffRepresentation,
              let bitmapImage = NSBitmapImageRep(data: tiffData),
              let fileData = bitmapImage.representation(using: .png, properties: [:]) else {
            print("写入失败")
            return false
        }
        
        do {
            try fileData.write(to: url)
            return true
        } catch {
            print("保存失败: \(error.localizedDescription)")
            return false
        }
    }
}
